{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "144c0eda",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入你的银行存款：100\n",
      "--------------------------------------------------欢迎来到蛋糕小店--------------------------------------------------\n",
      "商品编号\t\t商品名\t\t售价\n",
      "1\t\t草莓蛋糕\t\t20\n",
      "2\t\t巧克力棒\t\t5\n",
      "3\t\t蛋糕礼包\t\t80\n"
     ]
    }
   ],
   "source": [
    "# 1.定义容器，存储商城商品的信息 (-> 模拟的是：浏览某商城官网，在首页显示各种商品信息)\n",
    "goods_shop={\n",
    "    1:('草莓蛋糕',20),\n",
    "    2:('巧克力棒',5),\n",
    "    3:('蛋糕礼包',80)\n",
    "}\n",
    "# 2.从控制台动态接收客户的银行存款余额信息\n",
    "qian=int(input(\"请输入你的银行存款：\"))\n",
    "# 3.定义容器，存储所购买的一些商品信息（-> 模拟的是：进入商城，推着购物车准备存放一些货品）\n",
    "gouwuche={}\n",
    "# 4.通过循环，来模拟客户进入商城购物的情形\n",
    "while True:\n",
    "# (1) 显示商城中的商品信息\n",
    "    print('-'*50+\"欢迎来到蛋糕小店\"+'-'*50)\n",
    "    print('商品编号\\t\\t商品名\\t\\t售价')\n",
    "    for id in goods_shop:\n",
    "        goods_name=goods_shop[id][0]\n",
    "        goods_price=goods_shop[id][1]\n",
    "        print(f\"{id}\\t\\t{goods_name}\\t\\t{goods_price}\")\n",
    "# (2) 从退控制台动态接收用户所选购的商品的编号(0->出)\n",
    "    user_choice = int(input(\"请录入您所选购的商品的编号(若是选择0,则退出商城):\"))\n",
    "    all_goods_num=list(goods_shop.keys())\n",
    "# (3) 动态根据用户选择的商品编号，进行购物操作\n",
    "#   ①若用户选择为0,就退出循环\n",
    "#   ②若用户选择的商品编号不在本商城所出售的商品之内，给出提示,重新选择\n",
    "#   ③进行正常购物\n",
    "#       a) 若银行卡余额 ≥ 商品的售价,正常购物(修改银行存款余额，将选购的商品添加到购物车中)\n",
    "#       b) 若银行卡余额 < 商品的售价，给出提示\n",
    "    if user_choice ==0:\n",
    "        print(\"离开商城了~~~~~~~~~~~~~~~~~~~\")\n",
    "        break\n",
    "    elif user_choice not in all_goods_num:\n",
    "        print(f\"您输入的商品编号{user_choice}不在{all_goods_num}中，是不是搞错了？(请重新输入)\")\n",
    "    else:\n",
    "        select_goods_shop=goods_shop[user_choice]\n",
    "        name= select_goods_shop[0]\n",
    "        price= select_goods_shop[1]\n",
    "        if qian >= price:\n",
    "            qian-=price\n",
    "            if name  in gouwuche:\n",
    "                gouwuche[name] += 1\n",
    "                print(f'您本次所选购的商品的售价是【{price}】元！您的存款余额还剩【{qian}】元')\n",
    "            else:\n",
    "                gouwuche[name]=1\n",
    "                print(f'您本次所选购的商品的售价是【{price}】元！您的存款余额还剩【{qian}】元')\n",
    " \n",
    "        else:\n",
    "            print(f'目前，您的银行存款余额是【{qian}】元，小于商品的售价【{price}】元,不能正常购物了！')\n",
    "        # 5.显示购物车中所选购的商品信息\n",
    "    if len(gouwuche) >= 1:\n",
    "        print(\"\\n购物车中您所选购的所有商品信息如下所示\")\n",
    "        print(\"商品名\\t\\t\\t件数\")\n",
    "        print(\"_\" * 25)\n",
    "        for name in gouwuche:\n",
    "            print(f\"{name}\\t\\t\\t{gouwuche[name]}\")\n",
    "        print()\n",
    "# 6.给出友好提示\n",
    "print(\"\\n谢谢您使用本系统！欢迎下次光临回顾！^_^\\n\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "74e42240",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
